<!DOCTYPE HTML>
<html lang="zh-hans" >
    <!-- Start book Python基础 -->
<!-- Start book Python基础 -->
    <head>
        <!-- head:start -->
<!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>运算符优先级 | Python基础</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="姜伟">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="gitbook/style.css">
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-prism/prism.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    
    <link rel="prev" href="chapter07.html" />
    

        <!-- head:end -->
<!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
<!-- body:start -->
        
    <div class="book"
        data-level="8"
        data-chapter-title="运算符优先级"
        data-filepath="chapter08.md"
        data-basepath="."
        data-revision="Mon Feb 03 2020 12:30:22 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="index.html">
                
                        <i class="fa fa-check"></i>
                        
                        学习目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter01.html">
            
                
                    <a href="chapter01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        整数类型操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter02.html">
            
                
                    <a href="chapter02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter03.html">
            
                
                    <a href="chapter03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        算数运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4" data-path="chapter04.html">
            
                
                    <a href="chapter04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        赋值运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5" data-path="chapter05.html">
            
                
                    <a href="chapter05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        比较运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="chapter06.html">
            
                
                    <a href="chapter06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        逻辑运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="chapter07.html">
            
                
                    <a href="chapter07.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        位运算符
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="8" data-path="chapter08.html">
            
                
                    <a href="./chapter08.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        运算符优先级
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本书使用 GitBook 发布
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="" >Python基础</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h2 id="&#x8FD0;&#x7B97;&#x7B26;&#x4F18;&#x5148;&#x7EA7;">&#x8FD0;&#x7B97;&#x7B26;&#x4F18;&#x5148;&#x7EA7;</h2>
<p>&#x5F53;&#x591A;&#x79CD;&#x8FD0;&#x7B97;&#x7B26;&#x505A;&#x6DF7;&#x5408;&#x8FD0;&#x7B97;&#x65F6;&#xFF0C;&#x5C31;&#x4F1A;&#x6D89;&#x53CA;&#x5230;&#x5148;&#x8FD0;&#x7B97;&#x54EA;&#x4E2A;&#xFF0C;&#x540E;&#x8FD0;&#x7B97;&#x54EA;&#x4E2A;&#x95EE;&#x9898;&#x3002;&#x4EE5;&#x4E0B;&#x8868;&#x683C;&#x5217;&#x51FA;&#x4E86;&#x4ECE;&#x6700;&#x9AD8;&#x5230;&#x6700;&#x4F4E;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x6240;&#x6709;&#x8FD0;&#x7B97;&#x7B26;&#xFF1A;</p>
<table>
<tbody><tr><th>&#x8FD0;&#x7B97;&#x7B26;</th><th>&#x63CF;&#x8FF0;</th></tr>
<tr>
<td>**</td>
<td>&#x6307;&#x6570; (&#x6700;&#x9AD8;&#x4F18;&#x5148;&#x7EA7;)</td>
</tr><tr>
<td>~ + -</td>
<td>&#x6309;&#x4F4D;&#x7FFB;&#x8F6C;, &#x4E00;&#x5143;&#x52A0;&#x53F7;&#x548C;&#x51CF;&#x53F7; (&#x6700;&#x540E;&#x4E24;&#x4E2A;&#x7684;&#x65B9;&#x6CD5;&#x540D;&#x4E3A; +@ &#x548C; -@)</td>
</tr><tr>
<td>* / % //</td>
<td>&#x4E58;&#xFF0C;&#x9664;&#xFF0C;&#x53D6;&#x6A21;&#x548C;&#x53D6;&#x6574;&#x9664;</td>
</tr><tr>
<td>+ -</td>
<td>&#x52A0;&#x6CD5;&#x51CF;&#x6CD5;</td>
</tr><tr>
<td>&gt;&gt; &lt;&lt;</td>
<td>&#x53F3;&#x79FB;&#xFF0C;&#x5DE6;&#x79FB;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr><tr>
<td>&amp;</td>
<td>&#x4F4D; &apos;AND&apos;</td>
</tr><tr>
<td>^ |</td>
<td>&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr><tr>
<td>&lt;= &lt; &gt; &gt;=</td>
<td>&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr><tr>
<td>&lt;&gt; == !=</td>
<td>&#x7B49;&#x4E8E;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr>
<tr>
<td>= %= /= //= -= += *= **=</td>
<td>&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr>
<tr>
<td>is is not</td>
<td>&#x8EAB;&#x4EFD;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr>
<tr>
<td>in not in</td>
<td>&#x6210;&#x5458;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr><tr>
<td>not&gt;and&gt;or</td>
<td>&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;</td>
</tr>
</tbody></table>


<h2 id="&#x7EC3;&#x4E60;">&#x7EC3;&#x4E60;</h2>
<pre><code class="lang-python">print(<span class="hljs-keyword">True</span> <span class="hljs-keyword">or</span> <span class="hljs-keyword">False</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">True</span>)
print(<span class="hljs-keyword">False</span> <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">False</span>)
print(<span class="hljs-keyword">True</span> <span class="hljs-keyword">or</span> <span class="hljs-keyword">True</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">False</span>)

a = <span class="hljs-number">2</span>
print(a ** <span class="hljs-number">3</span> &gt; <span class="hljs-number">5</span> <span class="hljs-keyword">and</span> a + <span class="hljs-number">2</span> &gt; <span class="hljs-number">3</span> <span class="hljs-keyword">or</span> a * <span class="hljs-number">4</span> + <span class="hljs-number">8</span> == <span class="hljs-number">16</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> a == <span class="hljs-keyword">True</span> <span class="hljs-keyword">and</span> -a &lt; <span class="hljs-number">0</span>)
</code></pre>
<h2 id="&#x603B;&#x7ED3;&#xFF1A;">&#x603B;&#x7ED3;&#xFF1A;</h2>
<p>&#x5728;&#x4EE5;&#x540E;&#x7684;&#x5B9E;&#x9645;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x591A;&#x79CD;&#x8FD0;&#x7B97;&#x7B26;&#x8FDB;&#x884C;&#x6DF7;&#x5408;&#x8FD0;&#x7B97;&#x65F6;&#xFF0C;<span style="color:red;font-weight:700">&#x5F3A;&#x70C8;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x5C0F;&#x62EC;&#x53F7;&#x6765;&#x624B;&#x52A8;&#x7684;&#x63A7;&#x5236;&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#xFF01;<span></span></span></p>
<pre><code class="lang-python">b = <span class="hljs-keyword">True</span> <span class="hljs-keyword">or</span> <span class="hljs-keyword">True</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">False</span>    <span class="hljs-comment"># bad </span>
c = <span class="hljs-keyword">True</span> <span class="hljs-keyword">or</span> (<span class="hljs-keyword">True</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">False</span>)  <span class="hljs-comment"># good</span>
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="chapter07.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 位运算符"><i class="fa fa-angle-left"></i></a>
        
        
    </div>
</div>

        
<script src="gitbook/app.js"></script>

    
    <script src="gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-copy-code-button/toggle.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"prism":{},"splitter":{},"copy-code-button":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
<!-- body:end -->
    </body>
    <!-- End of book Python基础 -->
<!-- End of book Python基础 -->
</html>
